package br.srv.full.geoProcessing.entities.roads;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.*;

import br.srv.full.geoProcessing.entities.PathWay;
import br.srv.full.geoProcessing.entities.localidades.Locale;
import javax.persistence.JoinColumn;
 

/**
 * Entity implementation class for Entity: Rodovias
 * 
 */
@Entity
@Table(name = "Road")
public class Road extends PathWay implements Serializable {

	private static final long serialVersionUID = 1L;

	private boolean adotaPNV = true;

	@Column(length = 3)
	private String codigo;

	@Temporal(TemporalType.DATE)
	@Basic(optional = false)
	@Column(nullable = true, insertable = true, updatable = false)
	private Date dataCadastro = new Date();

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private Integer id;

	@ManyToOne
	@JoinColumn(insertable = true, updatable = false, name = "jurisdicao", referencedColumnName = "codigo", nullable = false)
	private Jurisdicao jurisdicao;

	@Column(length = 50)
	private String nome;

	@ManyToOne(optional=true)
	@JoinColumn(insertable = true, updatable = false, name = "tipoRodovia", referencedColumnName = "codigo")
	private RoadType tipo;

	@ManyToOne
	@JoinColumn(insertable = true, updatable = false, name = "locale", referencedColumnName = "acronym")
	private  Locale locale;

	@Column(insertable=false, updatable = false, unique = true,length=10)
	@Basic(optional=true)
	private String codigoAdotado;
 
	/**
	 * @return the codigoAdotado
	 */
	public String getCodigoAdotado() {
		return this.codigoAdotado;
	}

	public Road() {
		super();
	}

	/**
	 * @param p_locale
	 * @param p_codigo
	 * @param p_jurisdicao
	 */
	public Road(Locale p_locale, String p_codigo, RoadType p_tipo,
			Jurisdicao p_jurisdicao) {
		setUf(p_locale);
		setCodigo(p_codigo);
		if (p_tipo != null)
			setTipo(p_tipo);
		else {
			setTipo(null);
			setAdotaPNV(false);
		}
		setJurisdicao(p_jurisdicao);
	}

	/**
	 * @return the adotaPNV
	 */
	public boolean getAdotaPNV() {
		return isAdotaPNV();
	}

	public String getCodigo() {
		return this.codigo;
	}

	/**
	 * @return the dataCadastro
	 */
	public Date getDataCadastro() {
		return this.dataCadastro;
	}

	public Integer getId() {
		return this.id;
	}

	/**
	 * @return the jurisdicao
	 */
	public Jurisdicao getJurisdicao() {
		return this.jurisdicao;
	}

	public String getNome() {
		return this.nome;
	}

	/**
	 * @return the tipo
	 */
	public RoadType getTipo() {
		return this.tipo;
	}

	/**
	 * @return the uf
	 */
	public Locale getUf() {
		return this.locale;
	}

	/**
	 * @return the adotaPNV
	 */
	public boolean isAdotaPNV() {
		return this.adotaPNV;
	}

	/**
	 * @param p_b
	 */
	public void setAdotaPNV(boolean p_b) {
		adotaPNV = p_b;

	}

	public void setCodigo(String codigo) {
		this.codigo = codigo;
	}

	/**
	 * @param p_dataCadastro
	 *            the dataCadastro to set
	 */
	public void setDataCadastro(Date p_dataCadastro) {
		this.dataCadastro = p_dataCadastro;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	/**
	 * @param p_jurisdicao
	 */
	private void setJurisdicao(Jurisdicao p_jurisdicao) {
		jurisdicao = p_jurisdicao;
	}

	public void setNome(String nome) {
		this.nome = nome;
	}

	/**
	 * @param p_tipo
	 *            the tipo to set
	 */
	public void setTipo(RoadType p_tipo) {
		this.tipo = p_tipo;
	}

	/**
	 * @param p_locale
	 *            the uf to set
	 */
	public void setUf(Locale p_locale) {
		this.locale = p_locale;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		if (getNome() != null && getNome().trim().length() > 0)
			return getUf().getAcronym() + "-" + getCodigo() + ", " + getNome();
		else
			return getUf().getAcronym() + "-" + getCodigo();
	}

	/**
	 * @param p_codigoAdotado
	 */
	public void setCodigoAdotado(String p_codigoAdotado) {
		codigoAdotado = p_codigoAdotado;
	}
 
}
